package com.print.ane.funs;

import java.io.File;

import android.content.Intent;
import android.net.Uri;

import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREObject;

public class InstallApp implements FREFunction {

	@Override
	public FREObject call(FREContext context, FREObject[] arg1) {
		String path = null;
		try{
			path = arg1[0].getAsString();
		}catch(Exception e){
			
		}
		if(path == null){
			return null;
		}
		
		//检查文件存在
		File file = new File(path);
		if(!file.exists()){
			return null;
		}
		
		//安装APK
		Intent intent = new Intent(Intent.ACTION_VIEW);
		intent.setDataAndType(Uri.fromFile(file),"application/vnd.android.package-archive");
		context.getActivity().startActivity(intent);
		try{
			return FREObject.newObject(true);
		}catch(Exception e){
			return null;
		}
	}

}
